home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zcpp_jae.zip / CPP.H < prev    next >
C/C++ Source or Header  |  1991-05-18  |  10KB  |  326 lines

  1.  
  2. /*
  3.  
  4.  
  5.  Copyright (C) 1990 Texas Instruments Incorporated.
  6.  
  7.  Permission is granted to any individual or institution to use, copy, modify,
  8.  and distribute this software, provided that this complete copyright and
  9.  permission notice is maintained, intact, in all copies and supporting
  10.  documentation.
  11.  
  12.  Texas Instruments Incorporated provides this software "as is" without
  13.  express or implied warranty.
  14.  
  15.  
  16.  *    I n t e r n a l   D e f i n i t i o n s    f o r   C P P
  17.  *
  18.  * In general, definitions in this file should not be changed.
  19.  *
  20.  * Change History:
  21.  * 19-Jan-90  DKM   Added support for MVS and EBCDIC character set
  22.  * 27-Apr-91  gcg   Added support for void basic type.
  23.  */
  24.  
  25. #ifndef toupper
  26. #define toupper(c) ((c) + ('A' - 'a'))
  27. #endif /* no toupper */
  28. #ifndef tolower
  29. #define tolower(c) ((c) + ('a' - 'A'))
  30. #endif /* no tolower */
  31.  
  32. #ifndef    TRUE
  33. #define    TRUE        1
  34. #define    FALSE        0
  35. #endif
  36. #ifndef    EOS
  37. /*
  38.  * This is predefined in Decus C
  39.  */
  40. #define    EOS        '\0'        /* End of string        */
  41. #endif
  42. #define    EOF_CHAR    0        /* Returned by get() on eof    */
  43. #define NULLST        ((char *) NULL)    /* Pointer to nowhere (linted)    */
  44. #define    DEF_NOARGS    (-1)        /* #define foo vs #define foo()    */
  45. #define    DEF_BUILTIN    (-2)        /* Builtin defines              */
  46.  
  47. /*
  48.  * Non_display characters used for special markers.
  49.  *   The location of these is different in EBCDIC because the location
  50.  *   of the MAC_PARM table had be moved to start at char 1C.
  51.  */
  52. #if CHARSET == EBCDIC
  53. #define    DEF_MAGIC    0x19        /* Magic for #defines        */
  54. #define    TOK_SEP        0x1A        /* Token concatenation delim.    */
  55. #define COM_SEP        0x1B        /* Magic comment separator    */
  56. #else
  57. #define    DEF_MAGIC    0x1D        /* Magic for #defines        */
  58. #define    TOK_SEP        0x1E        /* Token concatenation delim.    */
  59. #define COM_SEP        0x1F        /* Magic comment separator    */
  60. #endif
  61.  
  62. /*
  63.  * Note -- in Ascii, the following will map macro formals onto DEL + the
  64.  * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
  65.  * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
  66.  * value is reserved for string substitution. 
  67.  *
  68.  * For EBCDIC, map macro formals x1C (decimal 28 + PAR_MAC) which
  69.  * also is OK as long as PAR_MAC is less than 33.  Note that this does
  70.  * overlap the code for BEL (decimal 47).  That means that you cannot
  71.  * use the  BEL char, ie '\a' in a #define macro.
  72.  */
  73. #if CHARSET == EBCDIC
  74. # define MAC_PARM        0x1C      /* Start at EBCDIC char x1C  */
  75. #else
  76. # define MAC_PARM     0x7F       /* Macro formals start here    */
  77. #endif
  78.  
  79. #if PAR_MAC >= 33
  80.     assertion fails -- PAR_MAC isn't less than 33
  81. #endif
  82. #define    LASTPARM    (PAR_MAC - 1)
  83.  
  84. /*
  85.  * Character type codes.
  86.  */
  87.  
  88. #define    INV        0        /* Invalid, must be zero    */
  89. #define    OP_EOE        INV        /* End of expression        */
  90. #define    DIG        1        /* Digit            */
  91. #define    LET        2        /* Identifier start        */
  92. #define    FIRST_BINOP    OP_ADD
  93. #define    OP_ADD        3
  94. #define    OP_SUB        4
  95. #define    OP_MUL        5
  96. #define    OP_DIV        6
  97. #define    OP_MOD        7
  98. #define    OP_ASL        8
  99. #define    OP_ASR        9
  100. #define    OP_AND        10        /* &, not &&            */
  101. #define    OP_OR        11        /* |, not ||            */
  102. #define    OP_XOR        12
  103. #define    OP_EQ        13
  104. #define    OP_NE        14
  105. #define    OP_LT        15
  106. #define    OP_LE        16
  107. #define    OP_GE        17
  108. #define    OP_GT        18
  109. #define    OP_ANA        19        /* &&                */
  110. #define    OP_ORO        20        /* ||                */
  111. #define    OP_QUE        21        /* ?                */
  112. #define    OP_COL        22        /* :                */
  113. #define    OP_CMA        23        /* , (relevant?)        */
  114. #define    LAST_BINOP    OP_CMA        /* Last binary operand        */
  115. /*
  116.  * The following are unary.
  117.  */
  118. #define    FIRST_UNOP    OP_PLU        /* First Unary operand        */
  119. #define    OP_PLU        24        /* + (draft ANSI standard)    */
  120. #define    OP_NEG        25        /* -                */
  121. #define    OP_COM        26        /* ~                */
  122. #define    OP_NOT        27        /* !                */
  123. #define    LAST_UNOP    OP_NOT
  124. #define    OP_LPA        28        /* (                */
  125. #define    OP_RPA        29        /* )                */
  126. #define    OP_END        30        /* End of expression marker    */
  127. #define    OP_MAX        (OP_END + 1)    /* Number of operators        */
  128. #define    OP_FAIL        (OP_END + 1)    /* For error returns        */
  129.  
  130. /*
  131.  * The following are for lexical scanning only.
  132.  */
  133.  
  134. #define    QUO        65        /* Both flavors of quotation    */
  135. #define    DOT        66        /* . might start a number    */
  136. #define    SPA        67        /* Space and tab        */
  137. #define    BSH        68        /* Just a backslash        */
  138. #define    END        69        /* EOF                */
  139.  
  140. /*
  141.  * These bits are set in ifstack[]
  142.  */
  143. #define    WAS_COMPILING    1        /* TRUE if compile set at entry    */
  144. #define    ELSE_SEEN    2        /* TRUE when #else processed    */
  145. #define    TRUE_SEEN    4        /* TRUE when #if TRUE processed    */
  146.  
  147. /*
  148.  * Define bits for the basic types and their adjectives
  149.  */
  150.  
  151. #define    T_CHAR          1
  152. #define    T_INT          2
  153. #define    T_FLOAT          4
  154. #define    T_DOUBLE      8
  155. #define    T_SHORT         16
  156. #define    T_LONG         32
  157. #define    T_SIGNED     64
  158. #define    T_UNSIGNED    128
  159. #define T_PTR        256
  160. #define    T_FPTR        512    /* Pointer to functions        */
  161. #ifdef VOID_SUPPORT
  162. #define T_VOID        1024
  163. #endif
  164.  
  165.  
  166. /*
  167.  * The DEFBUF structure stores information about #defined
  168.  * macros.  Note that the defbuf->repl information is always
  169.  * in malloc storage.
  170.  */
  171.  
  172. typedef struct defbuf {
  173.     struct defbuf    *link;        /* Next define in chain    */
  174.         void (*expander)();             /* pointer to expander function */
  175.     char        *repl;        /* -> replacement    */
  176.     int        hash;        /* Symbol table hash    */
  177.     int        nargs;        /* For define(args)    */
  178.     char        name[1];    /* #define name        */
  179. } DEFBUF;
  180.  
  181. /*
  182.  * The FILEINFO structure stores information about open files
  183.  * and macros being expanded.
  184.  */
  185. /* WARNING: This structure is duplicated in defmacio.h */
  186. typedef struct fileinfo {
  187.     char        *bptr;        /* Buffer pointer    */
  188.     int        line;        /* for include or macro    */
  189.     FILE        *fp;        /* File if non-null    */
  190.     struct fileinfo    *parent;    /* Link to includer    */
  191.     char        *filename;    /* File/macro name    */
  192.     char        *progname;    /* From #line statement    */
  193.     unsigned int    unrecur;    /* For macro recursion    */
  194.     char*        buffer;     /* current input line    */
  195. } FILEINFO;
  196.  
  197. /*
  198.  * The SIZES structure is used to store the values for #if sizeof
  199.  */
  200.  
  201. typedef struct sizes {
  202.     short    bits;            /* If this bit is set,        */
  203.     short    size;            /* this is the datum size value    */
  204.     short    psize;            /* this is the pointer size    */
  205. } SIZES;
  206. /*
  207.  * nomacarg is a built-in #define on Decus C.
  208.  */
  209.  
  210. #ifdef    nomacarg
  211. #define    cput        output        /* cput concatenates tokens    */
  212. #else
  213. #if COMMENT_INVISIBLE
  214. #define    cput(c)        { if (c != TOK_SEP && c != COM_SEP) putchar(c); }
  215. #else
  216. #define    cput(c)        { if (c != TOK_SEP) putchar(c); }
  217. #endif
  218. #endif
  219.  
  220. #ifndef    nomacarg
  221. #define    streq(s1, s2)    (strcmp(s1, s2) == 0)
  222. #endif
  223.  
  224. /*
  225.  * Error codes.  VMS uses system definitions.
  226.  * Decus C codes are defined in stdio.h.
  227.  * Others are cooked to order.
  228.  */
  229.  
  230. #if HOST == SYS_VMS
  231. #include        <ssdef.h>
  232. #include        <stsdef.h>
  233. #define IO_NORMAL    (SS$_NORMAL | STS$M_INHIB_MSG)
  234. #define    IO_ERROR    SS$_ABORT
  235. #endif
  236.  
  237. /*
  238.  * File access calls for OS2.
  239.  */
  240.  
  241. #if (HOST == SYS_OS2 || HOST == SYS_XENIX || HOST == SYS_VMS)
  242. #define F_OK        0    /* does file exist */
  243. #define X_OK        1    /* is it executable by caller */
  244. #define W_OK        2    /* writable by caller */
  245. #define R_OK        4    /* readable by caller */
  246. #endif
  247.  
  248. /* MVS headers already define F_OK, W_OK, and R_OK.  
  249.  * X_OK is not supported on MVS -- but we define it here
  250.  * to be the same as R_OK for cpp7.
  251.  */
  252. #if HOST == SYS_MVS
  253. #ifndef X_OK
  254. #define X_OK            R_OK    /* X_OK same as R_OK on MVS */
  255. #endif
  256. #endif
  257.  
  258. /*
  259.  * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
  260.  */
  261. #ifndef    IO_NORMAL
  262. #define    IO_NORMAL    0
  263. #endif
  264. #ifndef    IO_ERROR
  265. #define    IO_ERROR    1
  266. #endif
  267.  
  268. /*
  269.  * Externs
  270.  */
  271.  
  272. extern int    line;            /* Current line number        */
  273. extern int    wrongline;        /* Force #line to cc pass 1    */
  274. extern char    type[];            /* Character classifier        */
  275. extern char    *tokenbuf;        /* Current input token        */
  276. extern int    tokenbsize;        /* Current size allocated in tokenbuf
  277.                        (not counting 1 byte for zero) */
  278. extern int    instring;        /* TRUE if scanning string    */
  279. extern int    inmacro;        /* TRUE if scanning #define    */
  280. extern int    errors;            /* Error counter        */
  281. extern DEFBUF    *macro;                /* Catches start of infinite macro */
  282. extern int    recursion;        /* Macro depth counter        */
  283. extern char    ifstack[BLK_NEST];    /* #if information        */
  284. #define    compiling ifstack[0]
  285. extern char    *ifptr;            /* -> current ifstack item    */
  286. extern char    *incdir[NINCLUDE];    /* -i directories        */
  287. extern char    **incend;        /* -> active end of incdir    */
  288. extern int    cflag;            /* -C option (keep comments)    */
  289. extern int    eflag;            /* -E option (ignore errors)    */
  290. extern int    nflag;            /* -N option (no pre-defines)    */
  291. extern int    rec_recover;        /* unwind recursive macros    */
  292. extern char    *preset[];        /* Standard predefined symbols    */
  293. extern char    *magic[];        /* Magic predefined symbols    */
  294. extern FILEINFO    *infile;        /* Current input file        */
  295. extern char    work[NWORK + 1];    /* #define scratch        */
  296. extern char    *workp;            /* Free space in work        */
  297. extern int    debug;            /* Debug level            */
  298. extern int    keepcomments;        /* Don't remove comments if set    */
  299. extern SIZES    size_table[];        /* For #if sizeof sizes        */
  300. extern char    *getmem();        /* Get memory or die.        */
  301. extern char    *incmem();        /* Increase size of block or die.  */
  302. extern DEFBUF    *lookid();        /* Look for a #define'd thing    */
  303. extern DEFBUF    *defendel();        /* Symbol table enter/delete    */
  304. extern char    *savestring();        /* Stuff string in malloc mem.    */
  305. extern char    *strcpy();
  306. extern char    *strcat();
  307. extern char    *strrchr();
  308. extern char    *strchr();
  309.  
  310. #if HOST != SYS_MVS
  311. extern long    time();
  312. #endif
  313.  
  314. #if (HOST != SYS_OS2 && HOST != SYS_XENIX && HOST != SYS_MVS)
  315. extern char    *sprintf();        /* Lint needs this        */
  316. #endif
  317.  
  318. typedef int (*internal_expander) ();
  319.  
  320. struct expander_pair {
  321.   char* name;
  322.   internal_expander function;
  323. };
  324.  
  325. extern struct expander_pair internal_macros[]; /* defines internal macro expanders */
  326.